{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import math\n",
    "import random\n",
    "import operator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.read_csv?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ret_value10</th>\n",
       "      <th>ret_value20</th>\n",
       "      <th>factor_value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Timestamp</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>00:00.5</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:01.0</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:01.5</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:02.0</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:02.5</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           ret_value10  ret_value20  factor_value\n",
       "Timestamp                                        \n",
       "00:00.5      -0.091675    -0.129412           NaN\n",
       "00:01.0      -0.091675    -0.129412           NaN\n",
       "00:01.5      -0.091675    -0.129412           NaN\n",
       "00:02.0      -0.091675    -0.129412           NaN\n",
       "00:02.5      -0.091675    -0.129412           NaN"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv(\"test.csv\", index_col=\"Timestamp\")\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "factor = pd.read_csv(\"factor.csv\", index_col=\"Timestamp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Timestamp</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>00:00.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:01.0</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:01.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:02.0</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:02.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:03.0</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:03.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:04.0</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:04.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:05.0</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:05.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:06.0</th>\n",
       "      <td>3.191083</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:06.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:07.0</th>\n",
       "      <td>3.336003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:07.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:08.0</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:08.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:09.0</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:09.5</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:10.0</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  0\n",
       "Timestamp          \n",
       "00:00.5    0.000000\n",
       "00:01.0    0.000000\n",
       "00:01.5    0.000000\n",
       "00:02.0    0.000000\n",
       "00:02.5    0.000000\n",
       "00:03.0    0.000000\n",
       "00:03.5    0.000000\n",
       "00:04.0    0.000000\n",
       "00:04.5    0.000000\n",
       "00:05.0    0.000000\n",
       "00:05.5    0.000000\n",
       "00:06.0    3.191083\n",
       "00:06.5    0.000000\n",
       "00:07.0    3.336003\n",
       "00:07.5    0.000000\n",
       "00:08.0    0.000000\n",
       "00:08.5    0.000000\n",
       "00:09.0    0.000000\n",
       "00:09.5    0.000000\n",
       "00:10.0    0.000000"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor.head(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[\"factor_value2\"] = pd.DataFrame(factor.values, index=factor.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "ls = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.1910827025487154, 0.0, 3.3360028639618964, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.872360119937826, 1.7418810884169096, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.3360028639618964, 3.3360028639618964, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.3360028639618964, 0.0, 0.0, 3.1910827025487154, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.495364155267341, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.8868012498300901, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7274399585246455, 0.0, 0.0, 0.0, 0.43759963569828425, 0.0, 0.5825197971114648, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.724685818687558, 3.6258431867882575, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.724685818687558, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.43759963569828425, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.0, 0.0, 4.724685818687558, 0.0, 4.724685818687558, 0.0, 0.0, 4.724685818687558, 0.43759963569828425, 0.0, 0.0, 0.5825197971114648, 0.0, 0.43759963569828425, 0.43759963569828425, 4.724685818687558, 4.724685818687558, 4.724685818687558, 4.724685818687558, 4.724685818687558, 4.724685818687558, 0.0, 4.724685818687558, 0.0, 4.724685818687558, 4.724685818687558, 4.724685818687558, 4.724685818687558, 4.724685818687558, 0.0, 4.724685818687558, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7274399585246455, 0.872360119937826, 0.0, 0.0, 0.0, 0.0, 0.872360119937826, 0.0, 0.7274399585246455, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.14775931287192304, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.724685818687558, 0.0, 4.724685818687558, 0.0, 4.724685818687558, 0.0, 0.0, 4.724685818687558, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.724685818687558, 0.0, 0.0, 0.0, 0.29267947428510366, 0.0, 0.0, 0.0, 0.0, 4.724685818687558, 0.0, 0.0, 0.14775931287192304, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.14775931287192304, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5825197971114648, 0.0, 0.0, 0.0, 0.0, 0.0, 2.1766415726564516, 0.0, 2.1766415726564516, 2.1766415726564516, 2.1766415726564516, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.0, 3.9156835096146185, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.43759963569828425, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7274399585246455, 0.0, 0.7274399585246455, 0.7274399585246455, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.5825197971114648, 0.14775931287192304, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.14775931287192304, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.14775931287192304, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.29267947428510366, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.4520407655905485, 0.0, 1.4520407655905485, 1.4520407655905485, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.14775931287192304, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.0, 0.0028391514587424466, 0.29267947428510366, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.43759963569828425, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.43759963569828425, 0.0, 0.0, 0.0, 1.3071206041773678, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.0, 0.0, 0.0028391514587424466, 0.0, 0.0, 0.0, 0.0, 0.872360119937826, 0.0028391514587424466, 0.0028391514587424466, 0.0, 0.872360119937826, 0.0, 3.046162541135535, 0.0, 0.0, 4.724685818687558, 0.0, 0.0, 0.0, 0.0, 0.0, 1.4520407655905485, 3.6258431867882575, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.4520407655905485, 1.596960927003729, 1.596960927003729, 2.4664818954828127, 1.8868012498300901, 1.8868012498300901, 2.0317214112432707, 4.724685818687558, 4.724685818687558, 0.0, 0.0, 4.724685818687558, 4.724685818687558, 0.5825197971114648, 0.0, 0.0, 4.724685818687558, 0.5825197971114648, 0.43759963569828425, 3.6258431867882575, 0.29267947428510366, 0.29267947428510366, 0.29267947428510366, 4.724685818687558, 1.596960927003729, 0.0, 4.724685818687558, 4.724685818687558, 4.495364155267341, 4.640284316680521, 4.495364155267341, 1.1622004427641872, 1.1622004427641872, 4.724685818687558, 0.43759963569828425, 4.20552383244098, 0.0, 0.0, 4.20552383244098, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.756322218309174, 0.0, 1.596960927003729, 0.0, 0.0, 0.0, 0.0, 0.0, 1.1622004427641872, 0.0, 1.3071206041773678, 0.0, 0.0, 0.14775931287192304, 0.0, 0.14775931287192304, 0.0, 0.0, 0.0, 0.0, 0.0, 0.29267947428510366, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.724685818687558, 4.724685818687558, 1.3071206041773678, 0.0, 0.0, 0.0, 0.0, 0.0, 4.724685818687558, 0.0, 0.0, 0.43759963569828425, 0.0, 0.0, 4.724685818687558, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.3071206041773678]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[\"factor_value3\"] = pd.DataFrame(ls, index=factor.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ret_value10</th>\n",
       "      <th>ret_value20</th>\n",
       "      <th>factor_value</th>\n",
       "      <th>factor_value2</th>\n",
       "      <th>factor_value3</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Timestamp</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>08:11.0</th>\n",
       "      <td>-0.645826</td>\n",
       "      <td>-1.221218</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:11.5</th>\n",
       "      <td>-0.276392</td>\n",
       "      <td>-0.867414</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:12.0</th>\n",
       "      <td>0.488517</td>\n",
       "      <td>-0.508980</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:12.5</th>\n",
       "      <td>0.706934</td>\n",
       "      <td>-0.635503</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:13.0</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.514494</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:13.5</th>\n",
       "      <td>-0.276392</td>\n",
       "      <td>-0.635503</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:14.0</th>\n",
       "      <td>-0.279198</td>\n",
       "      <td>-0.762026</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:14.5</th>\n",
       "      <td>-0.645826</td>\n",
       "      <td>-0.888549</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:15.0</th>\n",
       "      <td>0.681914</td>\n",
       "      <td>-0.257773</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:15.5</th>\n",
       "      <td>0.289154</td>\n",
       "      <td>-0.259665</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:16.0</th>\n",
       "      <td>0.681914</td>\n",
       "      <td>0.002790</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:16.5</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.261614</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:17.0</th>\n",
       "      <td>-0.276392</td>\n",
       "      <td>0.147417</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:17.5</th>\n",
       "      <td>-0.466720</td>\n",
       "      <td>0.156370</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:18.0</th>\n",
       "      <td>0.095847</td>\n",
       "      <td>0.004798</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:18.5</th>\n",
       "      <td>0.283369</td>\n",
       "      <td>0.002790</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:19.0</th>\n",
       "      <td>0.098739</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:19.5</th>\n",
       "      <td>0.488517</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:20.0</th>\n",
       "      <td>0.636300</td>\n",
       "      <td>0.977903</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:20.5</th>\n",
       "      <td>0.277758</td>\n",
       "      <td>0.415707</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.307121</td>\n",
       "      <td>1.307121</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           ret_value10  ret_value20  factor_value  factor_value2  \\\n",
       "Timestamp                                                          \n",
       "08:11.0      -0.645826    -1.221218           NaN       0.000000   \n",
       "08:11.5      -0.276392    -0.867414           NaN       0.000000   \n",
       "08:12.0       0.488517    -0.508980           NaN       0.000000   \n",
       "08:12.5       0.706934    -0.635503           NaN       0.000000   \n",
       "08:13.0      -0.091675    -0.514494           NaN       0.000000   \n",
       "08:13.5      -0.276392    -0.635503           NaN       0.000000   \n",
       "08:14.0      -0.279198    -0.762026           NaN       0.000000   \n",
       "08:14.5      -0.645826    -0.888549           NaN       0.000000   \n",
       "08:15.0       0.681914    -0.257773           NaN       0.000000   \n",
       "08:15.5       0.289154    -0.259665           NaN       0.000000   \n",
       "08:16.0       0.681914     0.002790           NaN       0.000000   \n",
       "08:16.5      -0.091675    -0.261614           NaN       0.000000   \n",
       "08:17.0      -0.276392     0.147417           NaN       0.000000   \n",
       "08:17.5      -0.466720     0.156370           NaN       0.000000   \n",
       "08:18.0       0.095847     0.004798           NaN       0.000000   \n",
       "08:18.5       0.283369     0.002790           NaN       0.000000   \n",
       "08:19.0       0.098739    -0.129412           NaN       0.000000   \n",
       "08:19.5       0.488517    -0.129412           NaN       0.000000   \n",
       "08:20.0       0.636300     0.977903           NaN       0.000000   \n",
       "08:20.5       0.277758     0.415707           NaN       1.307121   \n",
       "\n",
       "           factor_value3  \n",
       "Timestamp                 \n",
       "08:11.0         0.000000  \n",
       "08:11.5         0.000000  \n",
       "08:12.0         0.000000  \n",
       "08:12.5         0.000000  \n",
       "08:13.0         0.000000  \n",
       "08:13.5         0.000000  \n",
       "08:14.0         0.000000  \n",
       "08:14.5         0.000000  \n",
       "08:15.0         0.000000  \n",
       "08:15.5         0.000000  \n",
       "08:16.0         0.000000  \n",
       "08:16.5         0.000000  \n",
       "08:17.0         0.000000  \n",
       "08:17.5         0.000000  \n",
       "08:18.0         0.000000  \n",
       "08:18.5         0.000000  \n",
       "08:19.0         0.000000  \n",
       "08:19.5         0.000000  \n",
       "08:20.0         0.000000  \n",
       "08:20.5         1.307121  "
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.tail(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "thre_value = data[\"factor_value\"].abs().quantile(0.6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "nan"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "thre_value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "y_mid_10_corr = temp_arr_data[\"factor_value\"].rolling(100).corr(temp_arr_data[\"ret_value10\"]).dropna().mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_data = data[\"factor_value\"].rolling(100).corr(data[\"ret_value10\"]).dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "ft100 = data[\"factor_value\"].tail(100)\n",
    "rt100 = data[\"ret_value10\"].tail(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.0"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(ft100.corr(rt100), 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp\n",
       "07:31.0   -0.916801\n",
       "07:31.5   -0.916801\n",
       "07:32.0   -0.916801\n",
       "07:32.5   -0.916801\n",
       "07:33.0   -0.916801\n",
       "             ...   \n",
       "08:18.5   -0.916801\n",
       "08:19.0   -0.916801\n",
       "08:19.5   -0.916801\n",
       "08:20.0   -0.916801\n",
       "08:20.5   -0.916801\n",
       "Name: factor_value, Length: 100, dtype: float64"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ft100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp\n",
       "07:31.0   -1.008952\n",
       "07:31.5   -1.217363\n",
       "07:32.0   -0.767088\n",
       "07:32.5   -0.091675\n",
       "07:33.0   -0.320995\n",
       "             ...   \n",
       "08:18.5    0.283369\n",
       "08:19.0    0.098739\n",
       "08:19.5    0.488517\n",
       "08:20.0    0.636300\n",
       "08:20.5    0.277758\n",
       "Name: ret_value10, Length: 100, dtype: float64"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rt100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp\n",
       "00:50.0   -0.335984\n",
       "00:50.5   -0.340402\n",
       "00:51.0   -0.344481\n",
       "00:51.5   -0.349388\n",
       "00:52.0   -0.353902\n",
       "dtype: float64"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp\n",
       "08:15.5    inf\n",
       "08:17.0    inf\n",
       "08:17.5    inf\n",
       "08:19.5    inf\n",
       "08:20.0    inf\n",
       "dtype: float64"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_data.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ret_value10</th>\n",
       "      <th>ret_value20</th>\n",
       "      <th>factor_value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Timestamp</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>00:01.0</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>0.963369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:01.5</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>-1.504132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:03.0</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>0.946616</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:04.0</th>\n",
       "      <td>-0.091675</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>-1.504132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00:05.5</th>\n",
       "      <td>0.772935</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>-1.504132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:15.5</th>\n",
       "      <td>0.289154</td>\n",
       "      <td>-0.259665</td>\n",
       "      <td>0.954782</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:18.5</th>\n",
       "      <td>0.283369</td>\n",
       "      <td>0.002790</td>\n",
       "      <td>0.947726</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:19.5</th>\n",
       "      <td>0.488517</td>\n",
       "      <td>-0.129412</td>\n",
       "      <td>0.955847</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:20.0</th>\n",
       "      <td>0.636300</td>\n",
       "      <td>0.977903</td>\n",
       "      <td>-1.504132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>08:20.5</th>\n",
       "      <td>0.277758</td>\n",
       "      <td>0.415707</td>\n",
       "      <td>-1.504132</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>405 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           ret_value10  ret_value20  factor_value\n",
       "Timestamp                                        \n",
       "00:01.0      -0.091675    -0.129412      0.963369\n",
       "00:01.5      -0.091675    -0.129412     -1.504132\n",
       "00:03.0      -0.091675    -0.129412      0.946616\n",
       "00:04.0      -0.091675    -0.129412     -1.504132\n",
       "00:05.5       0.772935    -0.129412     -1.504132\n",
       "...                ...          ...           ...\n",
       "08:15.5       0.289154    -0.259665      0.954782\n",
       "08:18.5       0.283369     0.002790      0.947726\n",
       "08:19.5       0.488517    -0.129412      0.955847\n",
       "08:20.0       0.636300     0.977903     -1.504132\n",
       "08:20.5       0.277758     0.415707     -1.504132\n",
       "\n",
       "[405 rows x 3 columns]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[data[\"factor_value\"].abs() >= thre_value]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp\n",
       "00:00.5    0.071981\n",
       "00:01.0    0.963369\n",
       "00:01.5    1.504132\n",
       "00:02.0    0.923826\n",
       "00:02.5    0.009585\n",
       "             ...   \n",
       "08:18.5    0.947726\n",
       "08:19.0    0.906860\n",
       "08:19.5    0.955847\n",
       "08:20.0    1.504132\n",
       "08:20.5    1.504132\n",
       "Name: factor_value, Length: 1000, dtype: float64"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"factor_value\"].abs()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    1000.00\n",
       "mean        0.00\n",
       "std         1.00\n",
       "min        -1.50\n",
       "25%        -1.44\n",
       "50%         0.50\n",
       "75%         0.87\n",
       "max         0.96\n",
       "Name: factor_value, dtype: float64"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(data[\"factor_value\"].describe(), 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "random.sample?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 3, 5, 8, 6]"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.sample(list(range(10)), 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n",
       "       nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"factor_value\"].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[nan, nan, nan]"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.sample(list(data[\"factor_value\"].values)[:10], 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.00000000e+00, 3.19108270e+00, 3.33600286e+00, 8.72360120e-01,\n",
       "       1.74188109e+00, 4.49536416e+00, 1.88680125e+00, 7.27439959e-01,\n",
       "       4.37599636e-01, 5.82519797e-01, 4.72468582e+00, 3.62584319e+00,\n",
       "       2.83915146e-03, 1.47759313e-01, 2.92679474e-01, 2.17664157e+00,\n",
       "       3.91568351e+00, 1.45204077e+00, 1.30712060e+00, 3.04616254e+00,\n",
       "       1.59696093e+00, 2.46648190e+00, 2.03172141e+00, 4.64028432e+00,\n",
       "       1.16220044e+00, 4.20552383e+00, 2.75632222e+00])"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"factor_value2\"].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp\n",
       "00:00.5   NaN\n",
       "00:01.0   NaN\n",
       "00:01.5   NaN\n",
       "00:02.0   NaN\n",
       "00:02.5   NaN\n",
       "           ..\n",
       "08:18.5   NaN\n",
       "08:19.0   NaN\n",
       "08:19.5   NaN\n",
       "08:20.0   NaN\n",
       "08:20.5   NaN\n",
       "Name: factor_value, Length: 1000, dtype: float64"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"factor_value\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "func_str = \"gp_add(gp_log(var0), gp_inv(var0))\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'gp_add(gp_log(var0), gp_inv(var0))'"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "func_str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'gp_add(gp_log(var0), gp_inv(var0))'"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "func_str.replace(\"var*\", \"a\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['19-1841']"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"19-1841\".split()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "phone = \"2004-959-559 # 这是一个国外电话号码\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [],
   "source": [
    "num = re.sub(r'#.*$', \"\", phone)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2004-959-559 '"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
